//
//  ViewController.m
//  WebJavascripeBridge
//
//  Created by xwx on 2018/8/24.
//  Copyright © 2018年 xwx. All rights reserved.
//

#import "ViewController.h"
#import "WebviewViewController.h"
#import "WXViewController.h"

#define ZOOMWAY_SCREEN_BOUNDS [UIScreen mainScreen].bounds
#define ZOOMWAY_SCREEN_WIDTH  [UIScreen mainScreen].bounds.size.width
#define ZOOMWAY_SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

static NSString *iden = @"cell-iden";

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tableview;
@property(nonatomic,strong)NSMutableArray *mutaArray;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.title = @"首页";
    
    [self _initViews];

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)_initViews{
    
    NSArray *array = @[@"WebViewJavascriptBridge",@"WKWebViewJavascriptBridge"];
    self.mutaArray = [NSMutableArray arrayWithArray:array];
    
    self.tableview = [[UITableView alloc]initWithFrame:ZOOMWAY_SCREEN_BOUNDS style:(UITableViewStylePlain)];
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    self.tableview.tableFooterView = [[UIView alloc]init];
    self.tableview.backgroundColor = [UIColor colorWithRed:204/255.0 green:204/255.0 blue:204/255.0 alpha:1];
    [self.view addSubview:self.tableview];
    
}


#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return self.mutaArray.count;
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:iden];
    
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:iden];
    }
    
    cell.textLabel.text = self.mutaArray[indexPath.row];
    cell.textLabel.font = [UIFont systemFontOfSize:16];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 55;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ZOOMWAY_SCREEN_WIDTH, 44)];
    view.backgroundColor = [UIColor lightGrayColor];
    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0;
}



#pragma mark -UITableViewDelegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    if (indexPath.row == 0) {
        
        WebviewViewController *w = [[WebviewViewController alloc]init];
        [self.navigationController pushViewController:w animated:YES];
    }else{
        
        WXViewController *w = [[WXViewController alloc]init];
        [self.navigationController pushViewController:w animated:YES];
        
    }

}

#pragma mark -控制器生命周期
-(void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
    [self.navigationController.navigationBar setTitleTextAttributes:
     
     @{NSFontAttributeName:[UIFont systemFontOfSize:18],
       
       NSForegroundColorAttributeName:[UIColor cyanColor]}];
    
    
}


@end
